<?php
namespace Application\Controller\Plugin;

use Zend\Mvc\Controller\Plugin\AbstractPlugin;

class FileUploader extends AbstractPlugin
{
	public function __invoke($fieldName='fileupload', $uploadPath=null)
	{
		if($uploadPath==null){
			$config = $this->controller->getServiceLocator()->get('config');
			$uploadPath = $config['module_config']['upload_location'];
		}
		
		//var_dump($uploadPath); return;
		
		$uploadFile = $this->controller->params()->fromFiles($fieldName);
		$adapter = new \Zend\File\Transfer\Adapter\Http();
		$adapter->setDestination($uploadPath);
		if ($adapter->receive($uploadFile['name'])) {
			return $uploadFile['name'];
		}
		return null;
	}
}